/*                     __      __  __ __  __                                   *\
**     ________ ___   / /  ___ \ \/ / \ \/ /                                   **
**    / __/ __// _ | / /  / _ | \  /   \  /    scalaxx - scala XML eXtensions  **
**  __\ \/ /__/ __ |/ /__/ __ | /  \   /  \    (c) Normen Mueller et al.       **
** /____/\___/_/ |_/____/_/ | |/_/\_\ /_/\_\   http://kwarc.info/nmueller      **
**                          |/                                                 **
\*                                                                             */

// $Id: TestXPath.scala 39 2009-11-01 12:10:24Z normen.mueller $

package tst.xml

import scala.xml._

import org.jaxen.{BaseXPath, DefaultNavigator, NamedAccessNavigator}
import org.jaxen.{JaxenException, UnsupportedAxisException, FunctionCallException}

private[xml] object TestXPath {
  def main(args: Array[String]): Unit = {
    // primitive conversion to scalaxx.xml
    val parser = scala.xml.parsing.ConstructingParser.fromSource(scala.io.Source.fromFile("src/tst/xml/addressbook.xml"), true)
    val doc: Document = parser.document
    val docelem: Node = doc.docElem    
    
    println("XPath: address")
    XPath("address", docelem).foreach(println(_))
    for (i <- 1 to 100) print("=")
    
    println("\nXPath: address[2]")
    XPath("address[2]", docelem).foreach(println(_))
    for (i <- 1 to 100) print("=")
    
    println("\nXPath: address/name[@gender='female']")
    XPath("address/name[@gender='female']", docelem).foreach(println(_))
    for (i <- 1 to 100) print("=")
    
    println("\nXPath: address/name[@gender='female']/..")
    XPath("address/name[@gender='female']/..", docelem).foreach(p => p match {
      case Some(p) => println(p)
      case _ => println(None)
    })
    for (i <- 1 to 100) print("=")
    
    println("\nXPath: /address[3]/phone[@type='home' and @confidential='yes']/text()")
    XPath("address[3]/phone[@type='home' and @confidential='yes']/text()", docelem).foreach(println(_))
    for (i <- 1 to 100) print("=")
    
    /*    
    XPath("//@type", docelem).foreach(println(_))
    XPath("/address[1]/@id", docelem).foreach(println(_))
    XPath("/address[1]/@id/text()", docelem).foreach(println(_))
    XPath("/address[2]/phone[1]/@type/text()", docelem).foreach(println(_))
    */
  }
}
